<?php
namespace Admin\Model;
use Think\Model;
class AdminModel extends Model{
	
	//1,自动验证		
	protected $patchValidate=true;
	//2,允许提交的字段 
	protected $insertFileds="admin_name.admin_password,admin_logintime,admin_power";//
	protected $_validate=[
		['admin_name','require','用户名必须填写',1],//
		['code','require','验证码必须填写',1],//
		['admin_password','require','密码必须填写',1],
		['admin_password','3,12','密码必须在3到12位之间',1,'length'],
		['admin_password','/^\w+$/','密码只能由数字,数字和下划线组成',1,'regex'],
	];
	
	

	protected function _before_insert(&$data,$option){
		
			$data['last_logintime']=time();//时间戳,便于对比
			
			
	}
	//检测用户名
	public function checkNamePwd($name,$pwd)
	{
		$z=$this->where("admin_name='$name' ")->find();
		if ($z) {
			if ($z['admin_password']==$pwd) {
				return $z;
			}
		}
		return null;

	}
}
	
	
?>